package com.gwnet.shop.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gwnet.shop.domain.ShopBanner;
import com.gwnet.shop.service.IShopBannerService;

import javax.annotation.Resource;

/**
 * 商城轮播图Controller
 * 
 * @author zhangwanpeng
 * @date 2024-08-08
 */
@RestController
@RequestMapping("/banner")
public class ShopBannerController extends MBaseController
{
    @Resource
    private IShopBannerService shopBannerService;

    /**
     * 查询商城轮播图列表
     */
    @SaCheckPermission("shop:banner:list")
    @GetMapping("/list")
    public TableDataInfo list(ShopBanner shopBanner)
    {
        startPage();
        List<ShopBanner> list = shopBannerService.selectShopBannerList(shopBanner);
        return getDataTable(list);
    }


    /**
     * 获取商城轮播图详细信息
     */
    @SaCheckPermission("shop:banner:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopBannerService.selectShopBannerById(id));
    }

    /**
     * 新增商城轮播图
     */
    @SaCheckPermission("shop:banner:add")
    @Log(title = "商城轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopBanner shopBanner)
    {
        shopBanner.setCreateBy( LoginHelper.getUserId() );
        return toAjax(shopBannerService.insertShopBanner(shopBanner));
    }

    /**
     * 修改商城轮播图
     */
    @SaCheckPermission("shop:banner:edit")
    @Log(title = "商城轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopBanner shopBanner)
    {
        shopBanner.setCreateBy( LoginHelper.getUserId() );
        return toAjax(shopBannerService.updateShopBanner(shopBanner));
    }

    /**
     * 删除商城轮播图
     */
    @SaCheckPermission("shop:banner:remove")
    @Log(title = "商城轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopBannerService.deleteShopBannerByIds(ids));
    }
}
